package ciicos.service.impl;

import ciicos.entity.*;
import ciicos.mapper.LineProjectMapper;
import ciicos.service.*;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import ciicos.util.RandomUtil;

import java.math.BigDecimal;

import cn.hutool.core.util.ObjectUtil;
import ciicos.permission.model.authorize.AuthorizeConditionModel;

import ciicos.util.GeneraterSwapUtil;
import ciicos.model.visiual.superQuery.ConditionJsonModel;
import ciicos.model.visiual.superQuery.SuperQueryJsonModel;
import ciicos.model.visiual.superQuery.SuperQueryConditionModel;


import ciicos.permission.service.AuthorizeService;


import java.lang.reflect.Field;

import com.baomidou.mybatisplus.annotation.TableField;

import java.util.stream.Collectors;

import ciicos.model.lineproject.*;


import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;

import java.text.SimpleDateFormat;

import ciicos.util.*;

import java.util.*;

import ciicos.base.model.filter.RuleInfo;
import ciicos.permission.util.GenUtil;

/**
 * 作业工程管理
 * 版本： V3.2.0
 * 版权：
 * 作者： 企业研发中心
 * 日期： 2025-10-06
 */
@Service
public class LineProjectServiceImpl extends ServiceImpl<LineProjectMapper, LineProjectEntity> implements LineProjectService {

    private final static Class eClass = LineProjectEntity.class;


    @Override
    public List<LineProjectEntity> getList(LineProjectPagination pagination) {
        String dataType = pagination.getDataType();
        QueryWrapper<LineProjectEntity> queryWrapper = new QueryWrapper<>();
        AutoCodeUtil.highQuery(pagination.getSuperQueryJson(),eClass,queryWrapper);
        if (ObjectUtil.isNotEmpty(pagination.getName())) {
            queryWrapper.lambda().like(LineProjectEntity::getName, pagination.getName());
        }

        if (ObjectUtil.isNotEmpty(pagination.getStatus())) {
            queryWrapper.lambda().eq(LineProjectEntity::getStatus, pagination.getStatus());
        }

        if (ObjectUtil.isNotEmpty(pagination.getLineplacetype())) {
            queryWrapper.lambda().eq(LineProjectEntity::getLineplacetype, pagination.getLineplacetype());
            if (ObjectUtil.isNotEmpty(pagination.getLineplaceid())) {
                queryWrapper.lambda().eq(LineProjectEntity::getLineplaceid, pagination.getLineplaceid());
            }
        }

        //排序+分页
        return AutoCodeUtil.sortPageList(this,queryWrapper, eClass,
                pagination.getSidx(), pagination.getSort(),
                LineProjectEntity::getId, true,pagination,StringUtil.equals("0",dataType));
    }

    @Override
    public LineProjectEntity getInfo(String id) {
        QueryWrapper<LineProjectEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(LineProjectEntity::getId, id);
        return this.getOne(queryWrapper);
    }

    @Override
    public void create(LineProjectEntity entity) {
        this.save(entity);
    }

    @Override
    public boolean update(String id, LineProjectEntity entity) {
        return this.updateById(entity);
    }

    @Override
    public void delete(LineProjectEntity entity) {
        if (entity != null) {
            this.removeById(entity.getId());
        }
    }
    //子表方法

    //列表子表数据方法


    //验证表单唯一字段
    @Override
    public String checkForm(LineProjectForm form, int i) {
        int total = 0;
        boolean isUp = StringUtil.isNotEmpty(form.getId()) && !form.getId().equals("0");
        String id = "";
        String countRecover = "";
        if (isUp) {
            id = form.getId();
        }

        return countRecover;
    }

    @Override
    public String getProjectStatusByLinePlace(String linePlaceType, String linePlaceId) {
        QueryWrapper<LineProjectEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.lambda().eq(LineProjectEntity::getLineplacetype, linePlaceType);
        queryWrapper.lambda().eq(LineProjectEntity::getLineplaceid, linePlaceId);
        LineProjectEntity lineProjectEntity = this.getOne(queryWrapper);
        if (lineProjectEntity != null) {
            return StringUtil.equals(lineProjectEntity.getStatus(), "1") ? "1" : "0";
        }
        return "0";


    }


}
